<template>
  <div>
    <el-button class="addButton" @click="addFormVisible = true">新增</el-button>
    <el-dialog
      title="新增一级类目"
      :visible.sync="addFormVisible"
      center
      :show-close="false"
    >
      <el-form :model="form">
        <el-form-item label="ID:" :label-width="formLabelWidth">
          <el-input
            v-model="form.id"
            :disabled="true"
            placeholder="系统默认"
            autocomplete="off"
          ></el-input>
        </el-form-item>

        <el-form-item label="上级类目:" :label-width="formLabelWidth">
          <el-select v-model="form.category" placeholder="请选择类别">
            <el-option label="百货食品" value="baihuo"></el-option>
            <el-option label="服装鞋包" value="fuzhuabg"></el-option>
            <el-option label="美妆饰品" value="meizhuabg"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="类目名称:" :label-width="formLabelWidth">
          <el-input
            :label-width="formLabelWidth"
            v-model="form.name"
          ></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer">
        <el-button @click="addFormVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmDialogClick">确定</el-button>
      </div>
    </el-dialog>

    <div style="margin-top: 20px">
      <el-table
        :data="tableData"
        stripe
        border
        max-height="350px"
        style="width: 100%"
      >
        <el-table-column prop="id" label="ID"></el-table-column>
        <el-table-column prop="category" label="类别名称"></el-table-column>
        <el-table-column prop="leve" label="级别"></el-table-column>
        <el-table-column prop="superLev" label="上级类别"></el-table-column>
        <el-table-column prop="createDate" label="创建时间"></el-table-column>
        <el-table-column prop="updateDate" label="更新时间"></el-table-column>
        <el-table-column label="设置" width="150">
          <template v-slot="scope">
            <el-button
              class="normalButton"
              @click="($event) => addClick(scope.row)"
              type="text"
              size="small"
              >新增下级</el-button
            >
            <el-button
              class="normalButton"
              @click="($event) => lookClick(scope.row.id)"
              type="text"
              size="small"
              >查看下级</el-button
            >
          </template>
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="150">
          <template v-slot="scope">
            <el-button
              class="normalButton"
              @click="($event) => addClick(scope.row)"
              type="text"
              size="small"
              >编辑</el-button
            >
            <el-button
              class="delButton"
              @click="($event) => lookClick(scope.row.id)"
              type="text"
              size="small"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: "categoryList",
  data() {
    return {
      tableData: [
        {
          id: 951,
          category: "2016-05-02",
          leve: "百货食品",
          superLev: 0,
          createDate: "2023年11月16日16:09",
          updateDate: "2023年11月16日16:10",
        },
        {
          id: 952,
          category: "2016-05-02",
          leve: "服装鞋包",
          superLev: 0,
          createDate: "2023年11月16日16:09",
          updateDate: "2023年11月16日16:10",
        },
        {
          id: 953,
          category: "2016-05-02",
          leve: "美妆饰品",
          superLev: 0,
          createDate: "2023年11月16日16:09",
          updateDate: "2023年11月16日16:10",
        },
      ],
      addFormVisible: false,
      form: {
        id: "",
        category: "",
        superCategory: ["服饰", "食品", "百货"],
        name: "",
      },
      formLabelWidth: "120px",
    };
  },
  computed: {},

  methods: {
    confirmDialogClick() {
      console.log("确定");
      this.addFormVisible = false;
    },

    addClick(row) {
      console.log(row);
    },
    lookClick(id) {
      console.log(id);
    },
  },
};
</script>

<style scoped>
.addButton {
  color: white;
  background-color: rgb(41, 59, 105);
}
.normalButton {
  color: rgb(51, 51, 51);
}
.delButton {
  color: rgb(190, 15, 1);
}
</style>
